
_realname=kdenlive
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=25.04.1
pkgrel=1
pkgdesc="A non-linear video editor for Linux using the MLT video framework (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: kdenlive'
)
msys2_repository_url='https://invent.kde.org/multimedia/kdenlive/'
url="https://kdenlive.org/"
license=("spdx:GPL-3.0-only")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
  "${MINGW_PACKAGE_PREFIX}-icoutils"
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
)
depends=(
  "${MINGW_PACKAGE_PREFIX}-breeze-icons"
  "${MINGW_PACKAGE_PREFIX}-frei0r-plugins"
  "${MINGW_PACKAGE_PREFIX}-karchive"
  "${MINGW_PACKAGE_PREFIX}-kbookmarks"
  "${MINGW_PACKAGE_PREFIX}-kcodecs"
  "${MINGW_PACKAGE_PREFIX}-kcolorscheme"
  "${MINGW_PACKAGE_PREFIX}-kcompletion"
  "${MINGW_PACKAGE_PREFIX}-kconfig"
  "${MINGW_PACKAGE_PREFIX}-kconfigwidgets"
  "${MINGW_PACKAGE_PREFIX}-kcoreaddons"
  "${MINGW_PACKAGE_PREFIX}-kcrash"
  "${MINGW_PACKAGE_PREFIX}-kfilemetadata"
  "${MINGW_PACKAGE_PREFIX}-kguiaddons"
  "${MINGW_PACKAGE_PREFIX}-ki18n"
  "${MINGW_PACKAGE_PREFIX}-kiconthemes"
  "${MINGW_PACKAGE_PREFIX}-kio"
  "${MINGW_PACKAGE_PREFIX}-kitemviews"
  "${MINGW_PACKAGE_PREFIX}-knewstuff"
  "${MINGW_PACKAGE_PREFIX}-knotifications"
  "${MINGW_PACKAGE_PREFIX}-knotifyconfig"
  "${MINGW_PACKAGE_PREFIX}-ktextwidgets"
  "${MINGW_PACKAGE_PREFIX}-kwidgetsaddons"
  "${MINGW_PACKAGE_PREFIX}-kxmlgui"
  "${MINGW_PACKAGE_PREFIX}-mlt"
  "${MINGW_PACKAGE_PREFIX}-opentimelineio"
  "${MINGW_PACKAGE_PREFIX}-purpose"
  "${MINGW_PACKAGE_PREFIX}-shared-mime-info"
  "${MINGW_PACKAGE_PREFIX}-qqc2-desktop-style"
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
  "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
  "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
  "${MINGW_PACKAGE_PREFIX}-qt6-networkauth"
  "${MINGW_PACKAGE_PREFIX}-qt6-svg"
  "${MINGW_PACKAGE_PREFIX}-solid"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-ffmpeg: For FFmpeg plugin"
  "${MINGW_PACKAGE_PREFIX}-mediainfo: For technical clip information"
  "${MINGW_PACKAGE_PREFIX}-opencv: For motion tracking"
)
source=("https://download.kde.org/stable/release-service/${pkgver}/src/${_realname}-$pkgver.tar.xz"{,.sig})
sha256sums=('ca01121fde6f52e415b5b84ff2f4d9ff689e03759b568bec005127125ab1e947'
            'SKIP')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87  # Christoph Feck <cfeck@kde.org>
              D81C0CB38EB725EF6691C385BB463350D6EF31EF) # Heiko Becker <heiko.becker@kde.org>
#options=("!strip" "debug")

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -GNinja \
    "${_extra_config[@]}" \
    -DBUILD_TESTING="OFF" \
    -DBUILD_QCH="OFF" \
    -DKDE_INSTALL_USE_QT_SYS_PATHS="OFF" \
    -DFETCH_OTIO="OFF" \
    -DUSE_DBUS="OFF" \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .

  # Move documentation to the correct location
  rm -rf "${pkgdir}${MINGW_PREFIX}/bin/data/doc"
  install -vDm 644 "${srcdir}"/${_realname}-${pkgver}/{AUTHORS,README.md} -t "${pkgdir}${MINGW_PREFIX}/share/doc/$_realname/"  
  install -vDm 644 "${srcdir}"/${_realname}-${pkgver}/LICENSES/* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/"
}
